<?php

use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Models\Role;

return [
    'title'=>'角色',
    'single'=>'角色',
    'model'=>Role::class,
    'permission'=>function(){
        return Auth::user()->can('manage_users');
    },
    'columns'=>[
        'id'=>[
            'title'=>'ID'
        ],
        'name'=>[
            'title'=>'角色名称'
        ],
        'permissions'=>[
            'title'=>'拥有的权限',
            'output'=>function($value,$model){
                $model->load('permissions');
                $result=[];
                foreach ($model->permissions as $permission){
                    $result[] = $permission->name;
                }
                return empty($result) ? 'N/A' : implode('   |   ',$result);
            },
            'sortable' => false
        ],
        'operation'=>[
            'title'=>'管理',
            'output'=>function($value,$model){
                return $value;
            },
            'sortable'=>false
        ]
    ],
    'edit_fields'=>[
        'name'=>[
            'title'=>'角色名称'
        ],
        'permissions'=>[
            'type'=>'relationship',
            'title'=>'拥有的权限',
            'name_field'=>'name'
        ]
    ],
    'filters'=>[
        'id'=>[
            'title'=>'ID'
        ],
        'name'=>[
            'title'=>'角色名称'
        ]
    ],
    'rules'=>[
        'name'=>'required|max:15|unique:users,name'
    ],
    'messages'=>[
        'name.required'=>'角色名称不能为空',
        'name:unique'=>'角色名称不能重复'
    ]
];
